#!/bin/bash
#获取本地路径
DIR=/opt/huisheng/wwwroot/api.raisound.com/html/instruction_platform_api
LOGDIR="/opt/huisheng/wwwroot/api.raisound.com/html/instruction_platform_api/logs"

case "$1" in
start)
  #echo $DIR
  #删除存在的pid文件
  #rm -rf $DIR'/vendor/workerman/_*'
  find $DIR'/vendor/workerman/' -type f -name '*.pid' | xargs rm

  #判断文件夹是否存在
  if [ ! -d $DIR$LOGDIR ];then
   mkdir $LOGDIR
  fi
  #开启进程

  #websocket start
  nohup php ${DIR}/think worker:gateway start >${LOGDIR}/gateway.log  2>&1 &
  sleep 1

  if [ -n "`ps aux | grep "WorkerMan" | grep -v grep `" ] 
  then
  echo -e "start gateway ---------------ok";
  else
  echo -e "start gateway ---------------fail";
  fi
  exit 0;
 ;;

stop)
  #判断文件夹是否存在
  if [ ! -d $LOGDIR ];then
  mkdir $LOGDIR
  fi
  #关闭服务
  echo php $DIR'/think worker:gateway' stop > $LOGDIR'/gateway.log' 
  php $DIR'/think worker:gateway' stop > $LOGDIR'/gateway.log'
  ;;
 esac
exit 0


